<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>OS工程基础 | whoway</title>
    <meta name="description" content="Personal Blog Website">
    <link rel="icon" href="/images/photo.jpg">
  <link rel="manifest" href="/images/photo.jpg">
  <link rel="apple-touch-icon" href="/images/photo.jpg">
  <meta http-quiv="pragma" cotent="no-cache">
  <meta http-quiv="pragma" cotent="no-cache,must-revalidate">
  <meta http-quiv="expires" cotent="0">
    
    <link rel="preload" href="/assets/css/0.styles.0dbae9ec.css" as="style"><link rel="preload" href="/assets/js/app.c70e21ad.js" as="script"><link rel="preload" href="/assets/js/68.68f45e5e.js" as="script"><link rel="prefetch" href="/assets/js/10.15222a53.js"><link rel="prefetch" href="/assets/js/100.7e0e5a86.js"><link rel="prefetch" href="/assets/js/101.efd59f25.js"><link rel="prefetch" href="/assets/js/102.dfbdc06c.js"><link rel="prefetch" href="/assets/js/103.d3ab2109.js"><link rel="prefetch" href="/assets/js/104.117957ef.js"><link rel="prefetch" href="/assets/js/105.046e8ff3.js"><link rel="prefetch" href="/assets/js/106.aebdc17d.js"><link rel="prefetch" href="/assets/js/107.248733c2.js"><link rel="prefetch" href="/assets/js/108.a2fecadc.js"><link rel="prefetch" href="/assets/js/109.35196857.js"><link rel="prefetch" href="/assets/js/11.770642f2.js"><link rel="prefetch" href="/assets/js/110.cf3d973c.js"><link rel="prefetch" href="/assets/js/111.f985889a.js"><link rel="prefetch" href="/assets/js/112.ad614f41.js"><link rel="prefetch" href="/assets/js/113.f666653c.js"><link rel="prefetch" href="/assets/js/114.c6c3f384.js"><link rel="prefetch" href="/assets/js/115.e51d3c2f.js"><link rel="prefetch" href="/assets/js/116.4f4b39f5.js"><link rel="prefetch" href="/assets/js/117.99352e11.js"><link rel="prefetch" href="/assets/js/118.c6ae6572.js"><link rel="prefetch" href="/assets/js/119.4ccbe778.js"><link rel="prefetch" href="/assets/js/12.042a92ff.js"><link rel="prefetch" href="/assets/js/120.edda1c4f.js"><link rel="prefetch" href="/assets/js/121.30a638ed.js"><link rel="prefetch" href="/assets/js/122.6efcefb1.js"><link rel="prefetch" href="/assets/js/123.91e6665b.js"><link rel="prefetch" href="/assets/js/124.f27e3d7e.js"><link rel="prefetch" href="/assets/js/125.c75712d5.js"><link rel="prefetch" href="/assets/js/126.ed756cce.js"><link rel="prefetch" href="/assets/js/127.2f06c74c.js"><link rel="prefetch" href="/assets/js/128.d5f6f30e.js"><link rel="prefetch" href="/assets/js/129.508b7eed.js"><link rel="prefetch" href="/assets/js/13.b5280c37.js"><link rel="prefetch" href="/assets/js/130.dc05f9aa.js"><link rel="prefetch" href="/assets/js/131.e0ba69b1.js"><link rel="prefetch" href="/assets/js/132.d79bcaa4.js"><link rel="prefetch" href="/assets/js/133.34acc01a.js"><link rel="prefetch" href="/assets/js/134.dabf64d5.js"><link rel="prefetch" href="/assets/js/135.ad90c915.js"><link rel="prefetch" href="/assets/js/136.dbb0074f.js"><link rel="prefetch" href="/assets/js/137.284ad365.js"><link rel="prefetch" href="/assets/js/138.a4b6856f.js"><link rel="prefetch" href="/assets/js/139.c9c1e20f.js"><link rel="prefetch" href="/assets/js/14.df02ba38.js"><link rel="prefetch" href="/assets/js/140.8b0a9269.js"><link rel="prefetch" href="/assets/js/141.9c7759c5.js"><link rel="prefetch" href="/assets/js/142.a4201a82.js"><link rel="prefetch" href="/assets/js/143.d7da6e8c.js"><link rel="prefetch" href="/assets/js/144.5e48e65d.js"><link rel="prefetch" href="/assets/js/145.a0e2633c.js"><link rel="prefetch" href="/assets/js/146.3c775f9b.js"><link rel="prefetch" href="/assets/js/147.22add89a.js"><link rel="prefetch" href="/assets/js/148.cfde1009.js"><link rel="prefetch" href="/assets/js/149.ffc835b5.js"><link rel="prefetch" href="/assets/js/15.fbdfc4ee.js"><link rel="prefetch" href="/assets/js/150.406c4b20.js"><link rel="prefetch" href="/assets/js/151.b2040eea.js"><link rel="prefetch" href="/assets/js/152.7bc65661.js"><link rel="prefetch" href="/assets/js/153.1d7c65e3.js"><link rel="prefetch" href="/assets/js/154.1309de49.js"><link rel="prefetch" href="/assets/js/155.81d3ee1f.js"><link rel="prefetch" href="/assets/js/156.154a4ef2.js"><link rel="prefetch" href="/assets/js/16.e5eb6147.js"><link rel="prefetch" href="/assets/js/17.57853c4a.js"><link rel="prefetch" href="/assets/js/18.cb9d7518.js"><link rel="prefetch" href="/assets/js/19.f354dc47.js"><link rel="prefetch" href="/assets/js/2.570d8a23.js"><link rel="prefetch" href="/assets/js/20.b5af7fad.js"><link rel="prefetch" href="/assets/js/21.0b1928fe.js"><link rel="prefetch" href="/assets/js/22.f78666de.js"><link rel="prefetch" href="/assets/js/23.29c3f366.js"><link rel="prefetch" href="/assets/js/24.6f596516.js"><link rel="prefetch" href="/assets/js/25.14067b60.js"><link rel="prefetch" href="/assets/js/26.74ba4989.js"><link rel="prefetch" href="/assets/js/27.13d60edd.js"><link rel="prefetch" href="/assets/js/28.9523cb32.js"><link rel="prefetch" href="/assets/js/29.8ec842e9.js"><link rel="prefetch" href="/assets/js/3.3fb3d2e0.js"><link rel="prefetch" href="/assets/js/30.805597a8.js"><link rel="prefetch" href="/assets/js/31.831b195d.js"><link rel="prefetch" href="/assets/js/32.063c672d.js"><link rel="prefetch" href="/assets/js/33.6d93fac3.js"><link rel="prefetch" href="/assets/js/34.56e8263c.js"><link rel="prefetch" href="/assets/js/35.dbe688bb.js"><link rel="prefetch" href="/assets/js/36.dc5af2c1.js"><link rel="prefetch" href="/assets/js/37.0a7494f6.js"><link rel="prefetch" href="/assets/js/38.fe4fc171.js"><link rel="prefetch" href="/assets/js/39.f5ed5e92.js"><link rel="prefetch" href="/assets/js/4.2c405ec8.js"><link rel="prefetch" href="/assets/js/40.fe7e2714.js"><link rel="prefetch" href="/assets/js/41.30b0811d.js"><link rel="prefetch" href="/assets/js/42.76f52d62.js"><link rel="prefetch" href="/assets/js/43.e7bb0817.js"><link rel="prefetch" href="/assets/js/44.ead0e883.js"><link rel="prefetch" href="/assets/js/45.235df046.js"><link rel="prefetch" href="/assets/js/46.5f09e829.js"><link rel="prefetch" href="/assets/js/47.67116354.js"><link rel="prefetch" href="/assets/js/48.31f34543.js"><link rel="prefetch" href="/assets/js/49.10b5ebba.js"><link rel="prefetch" href="/assets/js/5.6f47322c.js"><link rel="prefetch" href="/assets/js/50.c0f0b7f1.js"><link rel="prefetch" href="/assets/js/51.5143f3bf.js"><link rel="prefetch" href="/assets/js/52.eeddfd48.js"><link rel="prefetch" href="/assets/js/53.eb790db5.js"><link rel="prefetch" href="/assets/js/54.8fe5421c.js"><link rel="prefetch" href="/assets/js/55.d8f9004b.js"><link rel="prefetch" href="/assets/js/56.62ac9b92.js"><link rel="prefetch" href="/assets/js/57.a9caec0d.js"><link rel="prefetch" href="/assets/js/58.f93fc522.js"><link rel="prefetch" href="/assets/js/59.a81a03aa.js"><link rel="prefetch" href="/assets/js/6.8c2ea393.js"><link rel="prefetch" href="/assets/js/60.ab782775.js"><link rel="prefetch" href="/assets/js/61.6dd12daf.js"><link rel="prefetch" href="/assets/js/62.76f4b01f.js"><link rel="prefetch" href="/assets/js/63.6f8a4742.js"><link rel="prefetch" href="/assets/js/64.6f8bb1fa.js"><link rel="prefetch" href="/assets/js/65.4120a44b.js"><link rel="prefetch" href="/assets/js/66.360c2d2b.js"><link rel="prefetch" href="/assets/js/67.26f84d32.js"><link rel="prefetch" href="/assets/js/69.e311eb56.js"><link rel="prefetch" href="/assets/js/7.6762b2d7.js"><link rel="prefetch" href="/assets/js/70.cea82674.js"><link rel="prefetch" href="/assets/js/71.783ddcf7.js"><link rel="prefetch" href="/assets/js/72.e5467385.js"><link rel="prefetch" href="/assets/js/73.b8fb681b.js"><link rel="prefetch" href="/assets/js/74.1bae37db.js"><link rel="prefetch" href="/assets/js/75.024387e5.js"><link rel="prefetch" href="/assets/js/76.a8e53010.js"><link rel="prefetch" href="/assets/js/77.8c55500a.js"><link rel="prefetch" href="/assets/js/78.7ce90bf5.js"><link rel="prefetch" href="/assets/js/79.ef71713f.js"><link rel="prefetch" href="/assets/js/8.788a6364.js"><link rel="prefetch" href="/assets/js/80.acad589d.js"><link rel="prefetch" href="/assets/js/81.02670d10.js"><link rel="prefetch" href="/assets/js/82.53b7b1ac.js"><link rel="prefetch" href="/assets/js/83.99eb8581.js"><link rel="prefetch" href="/assets/js/84.d1535ce3.js"><link rel="prefetch" href="/assets/js/85.fe2b7de9.js"><link rel="prefetch" href="/assets/js/86.41850272.js"><link rel="prefetch" href="/assets/js/87.1cdc6df9.js"><link rel="prefetch" href="/assets/js/88.01bf3461.js"><link rel="prefetch" href="/assets/js/89.17c69819.js"><link rel="prefetch" href="/assets/js/9.3813842d.js"><link rel="prefetch" href="/assets/js/90.f6ae7e35.js"><link rel="prefetch" href="/assets/js/91.507bc284.js"><link rel="prefetch" href="/assets/js/92.90551782.js"><link rel="prefetch" href="/assets/js/93.dc442d78.js"><link rel="prefetch" href="/assets/js/94.315f4e94.js"><link rel="prefetch" href="/assets/js/95.ccd6c6bf.js"><link rel="prefetch" href="/assets/js/96.0c6d89d0.js"><link rel="prefetch" href="/assets/js/97.1a9f10a9.js"><link rel="prefetch" href="/assets/js/98.43be3caa.js"><link rel="prefetch" href="/assets/js/99.54c8207b.js">
    <link rel="stylesheet" href="/assets/css/0.styles.0dbae9ec.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">whoway</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link router-link-active">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link router-link-active">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>OS工程基础</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_1-”后台开发“概念辨析" class="sidebar-link">1.”后台开发“概念辨析</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_1-1-cpu密集型和i-o密集型" class="sidebar-link">1.1.CPU密集型和I/O密集型</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_1-2-同步和异步" class="sidebar-link">1.2.同步和异步</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_1-3-阻塞和非阻塞和轮询" class="sidebar-link">1.3.阻塞和非阻塞和轮询</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_1-4-xx池" class="sidebar-link">1.4.XX池</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_1-5-上下文切换" class="sidebar-link">1.5.上下文切换</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_1-6-tlb" class="sidebar-link">1.6.TLB</a></li></ul></li><li><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-大小端之争" class="sidebar-link">2.大小端之争</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#大端和小端存储-引子" class="sidebar-link">大端和小端存储-引子</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-1-概念" class="sidebar-link">2.1.概念</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-2-具体的，大端法和小端法的应用" class="sidebar-link">2.2.具体的，大端法和小端法的应用</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-3-大端法和小端法导致的问题：" class="sidebar-link">2.3.大端法和小端法导致的问题：</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-4-如何判别大端和小端" class="sidebar-link">2.4.如何判别大端和小端</a></li></ul></li><li><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_3-概念辨析" class="sidebar-link">3.概念辨析</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_3-1-终端" class="sidebar-link">3.1.终端</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_3-2-僵尸进程（zombie）" class="sidebar-link">3.2.僵尸进程（Zombie）</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_3-3-孤儿进程" class="sidebar-link">3.3.孤儿进程</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_3-4-init-进程" class="sidebar-link">3.4.init 进程</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-5-内核" class="sidebar-link">2.5.内核</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-6-进程组（作业）" class="sidebar-link">2.6.进程组（作业）</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-7-会话（session）" class="sidebar-link">2.7.会话（session）</a></li><li class="sidebar-sub-header"><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#_2-8-守护进程（daemon）『后台开发核心』" class="sidebar-link">2.8.守护进程（daemon）『后台开发核心』</a></li></ul></li><li><a href="/03.Software/02.OS/01.%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E9%9D%A2%E8%AF%95%E6%A6%82%E5%BF%B5.html#参考资料" class="sidebar-link">参考资料</a><ul class="sidebar-sub-headers"></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="os工程基础"><a href="#os工程基础" class="header-anchor">#</a> OS工程基础</h1> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>&lt;font style=&quot;background:yellow&quot;&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>[TOC]</p> <table><thead><tr><th>硬件</th> <th>OS管理</th> <th>说明</th></tr></thead> <tbody><tr><td>CPU（控制器和运算器）</td> <td>进程管理</td> <td></td></tr> <tr><td>I/O（输入和输出）</td> <td>I/O管理</td> <td>网络数据传输、中断、缓冲区</td></tr> <tr><td>存储器</td> <td>内存管理、外存管理</td> <td>寄存器、内存、固态/机械硬盘</td></tr></tbody></table> <h2 id="_1-”后台开发“概念辨析"><a href="#_1-”后台开发“概念辨析" class="header-anchor">#</a> 1.”后台开发“概念辨析</h2> <h3 id="_1-1-cpu密集型和i-o密集型"><a href="#_1-1-cpu密集型和i-o密集型" class="header-anchor">#</a> 1.1.CPU密集型和I/O密集型</h3> <h4 id="cpu密集型（cpu-bound）"><a href="#cpu密集型（cpu-bound）" class="header-anchor">#</a> CPU密集型（CPU-bound）</h4> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>CPU密集型也叫计算密集型，英文为CPU-bound，直译为CPU『受限』型
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><blockquote><p>特点：</p></blockquote> <ul><li>1.是要进行大量的计算，<font style="background:yellow;">消耗CPU资源</font></li> <li>2.这种计算密集型任务虽然也可以用多任务完成，但是<font style="background:yellow;">任务越多，花在『任务切换』的时间就越多，CPU执行任务的『效率』就越低</font></li> <li>3.要最高效地利用CPU，计算密集型任务同时进行的数量应当<strong>等于</strong>CPU的核心数。</li></ul> <h4 id="i-o密集型（i-o-bound）"><a href="#i-o密集型（i-o-bound）" class="header-anchor">#</a> I/O密集型（I/O-bound）</h4> <ul><li>IO密集型，涉及到<font style="background:yellow;">网络、磁盘IO</font>的任务都是IO密集型任务</li> <li>这类任务的特点是<strong>CPU消耗很少</strong>，任务的<strong>大部分时间都在等待IO操作完成</strong>（因为IO的速度远远低于CPU和内存的速度）</li> <li>对于IO密集型任务，<font style="background:yellow;">任务越多，CPU效率越高，但也有一个限度</font>。常见的大部分任务都是IO密集型任务，比如Web应用。</li></ul> <blockquote><p>参考资料：</p></blockquote> <ul><li>维基百科：<a href="https://zh.wikipedia.org/wiki/CPU%E5%AF%86%E9%9B%86%E5%9E%8B" target="_blank" rel="noopener noreferrer">CPU密集型<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li> <li>廖雪峰描述<a href="https://www.liaoxuefeng.com/wiki/897692888725344/945570591695328" target="_blank" rel="noopener noreferrer">CPU密集型和I/O密集型<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <h3 id="_1-2-同步和异步"><a href="#_1-2-同步和异步" class="header-anchor">#</a> 1.2.同步和异步</h3> <ul><li>同步（Synchronization）</li> <li>异步（asynchronous）</li></ul> <h3 id="_1-3-阻塞和非阻塞和轮询"><a href="#_1-3-阻塞和非阻塞和轮询" class="header-anchor">#</a> 1.3.阻塞和非阻塞和轮询</h3> <ul><li>阻塞（blocking）</li> <li>非阻塞（ non-blocking）</li> <li>轮询（polling）</li></ul> <h3 id="_1-4-xx池"><a href="#_1-4-xx池" class="header-anchor">#</a> 1.4.XX池</h3> <ul><li>进程池</li> <li>线程池</li> <li>数据库连接池</li></ul> <p>线程池</p> <ul><li>线程池：是由服务器预先创建的一组子线程</li></ul> <p>下文参考自：<a href="https://mp.weixin.qq.com/s?__biz=MzI1NTE3OTk4Nw==&mid=2653734974&idx=1&sn=987f9a4cfea1c830036ae20fc04866d5&chksm=f1e18582c6960c941a5e147c198d9cbc3f27e88dbb82fb62f0d23261821070bd43bdfd2fc2b2&mpshare=1&scene=23&srcid=0728Ab0PK8WsIZWsv1UoVm8L&sharer_sharetime=1595948760667&sharer_shareid=7d02bdfe8ee477ab2b773f2df63f3163#rd" target="_blank" rel="noopener noreferrer">链接<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <h4 id="（1）什么是线程池？"><a href="#（1）什么是线程池？" class="header-anchor">#</a> （1）什么是线程池？</h4> <p>实际开发中我们需要让程序执行某个特定任务时，就会开启一个线程，如果并发的线程数量太多，频繁地创建线程就会严重影响系统的运行效率。</p> <ul><li>如何解决上述为呢？有没有一种方式可以让线程得到复用？</li> <li>也就是要求执行一次任务之后不被销毁，可以继续执行其他任务，这就跟“数据库连接池”的思路一样了，数据库连接池的实现逻辑是在缓冲池中预先放置一定数量的连接对象，然后进行复用，那么很显然，在缓冲池中<b>预先放置一定数量的线程对象</b>以实现复用的机制就叫做线程池。</li></ul> <h4 id="（2）线程池的优点"><a href="#（2）线程池的优点" class="header-anchor">#</a> （2）线程池的优点</h4> <ul><li>1.使用线程池可以减少创建和销毁线程的次数，每个工作线程都可以重复使用。</li> <li>2.可以根据系统的承受能力，调整线程池中工作线程的数量，防止因为消耗过多内存导致服务器崩溃。</li></ul> <h3 id="_1-5-上下文切换"><a href="#_1-5-上下文切换" class="header-anchor">#</a> 1.5.上下文切换</h3> <ul><li>定义：<strong>上下文切换</strong>(英语：context switch)，又称<strong>环境切换</strong>，电脑术语，是一个<strong>存储</strong>和<strong>重建</strong>CPU的<strong>状态</strong> (<strong>内文</strong>)，因此令多个进程(process)可以分享单一CPU资源的计算过程。要切换CPU上的进程时，必需先行存储目前进程的状态，再将欲运行的进程之状态读回CPU中。</li> <li>开销：上下文切换通常是『<strong>计算密集型</strong>』的，『<strong>操作系统中的许多设计都是针对上下文切换的优化</strong>』。在进程间切换需要消耗一定的时间进行相关的管理工作——包括寄存器和内存映射的保存与读取、更新各种内部的表等等。处理器或者操作系统不同，上下文切换时所涉及的内容也不尽相同。比如在Linux内核中，上下文切换需要涉及寄存器、栈指针、程序计数器的切换，但和地址空间的切换无关（虽然进程在进行上下文切换时也需要做地址空间的切换）[2][3]。用户态线程之间也会发生类似的上下文切换，但这样的切换非常轻量。</li></ul> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>『CPU 寄存器』和『程序计数器』就是 CPU 上下文，因为它们都是 CPU 在运行任何任务前，必须的依赖环境。

CPU 寄存器是 CPU 内置的容量小、但速度极快的内存。『这是个比方，不是真实的』
程序计数器则是用来存储 CPU 正在执行的指令位置、或者即将执行的下一条指令位置。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><ul><li>根据 Tsuna 的测试报告，每次上下文切换都需要『<strong>几十ns到数us</strong>』的 CPU 时间。这个时间还是相当可观的，特别是在进程上下文切换次数较多的情况下，很容易导致 CPU 将大量时间耗费在寄存器、内核栈以及虚拟内存等资源的保存和恢复上，进而大大缩短了真正运行进程的时间。这也正是导致平均负载升高的一个重要因素。</li> <li>另外，我们知道， Linux 通过 <strong>TLB（Translation Lookaside Buffer）<strong>来管理虚拟内存到物理内存的映射关系。当虚拟内存更新后，T</strong>LB 也需要刷新，内存的访问也会随之变慢『因为命中的原因』</strong>。特别是在多处理器系统上，缓存是被多个处理器共享的，刷新缓存不仅会影响当前处理器的进程，还会影响共享缓存的其他处理器的进程。</li></ul> <blockquote><p>维基百科：<a href="https://zh.wikipedia.org/wiki/%E4%B8%8A%E4%B8%8B%E6%96%87%E4%BA%A4%E6%8F%9B" target="_blank" rel="noopener noreferrer">上下文切换<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p>知乎：<a href="https://zhuanlan.zhihu.com/p/52845869" target="_blank" rel="noopener noreferrer">上下文切换<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></blockquote> <h3 id="_1-6-tlb"><a href="#_1-6-tlb" class="header-anchor">#</a> 1.6.TLB</h3> <ul><li><p>TLB（Translation Lookaside Buffer，<strong>转译后备缓冲器</strong>/页表缓存）</p></li> <li><p>在中国大陆被翻译为<strong>页表缓存</strong>、<strong>转址旁路缓存</strong>，为<a href="https://zh.wikipedia.org/wiki/%E4%B8%AD%E5%A4%AE%E8%99%95%E7%90%86%E5%99%A8" target="_blank" rel="noopener noreferrer">CPU<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>的一种缓存，由<a href="https://zh.wikipedia.org/wiki/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E5%8D%95%E5%85%83" target="_blank" rel="noopener noreferrer">存储器管理单元<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>用于改进<a href="https://zh.wikipedia.org/wiki/%E8%99%9B%E6%93%AC%E4%BD%8D%E5%9D%80" target="_blank" rel="noopener noreferrer">虚拟地址<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>到物理地址的转译速度</p></li> <li><p>『进程』切换期间，TLB会被刷新，从而使内存访问在一段时间内变得更加昂贵。</p></li></ul> <blockquote><p>知乎：<a href="https://zhuanlan.zhihu.com/p/108425561" target="_blank" rel="noopener noreferrer">TLB原理<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p>维基百科：<a href="https://zh.wikipedia.org/wiki/%E8%BD%89%E8%AD%AF%E5%BE%8C%E5%82%99%E7%B7%A9%E8%A1%9D%E5%8D%80" target="_blank" rel="noopener noreferrer">TLB原理<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></blockquote> <h2 id="_2-大小端之争"><a href="#_2-大小端之争" class="header-anchor">#</a> 2.大小端之争</h2> <ul><li>大小端（BigEndianLittleEndian）</li></ul> <h3 id="大端和小端存储-引子"><a href="#大端和小端存储-引子" class="header-anchor">#</a> 大端和小端存储-引子</h3> <ul><li>《格列夫游记》一书中讲到，格列佛在小人国中，遇到了“<a href="https://blog.csdn.net/linghaidong/article/details/50242233" target="_blank" rel="noopener noreferrer">大小端<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>的事情”。在计算机界，也有一个类似的大端小端之争，随着计算机的发展，历史告诉我们，这些都是合理的，但是要在计算机间合理通信或者理解计算机底层的时候，你自己记得转换就好了。</li></ul> <h3 id="_2-1-概念"><a href="#_2-1-概念" class="header-anchor">#</a> 2.1.概念</h3> <p>大端：指低字节存储在高地址。
小端：指低字节存储在低地址。</p> <p><strong>记忆方法：</strong></p> <p><font style="background:yellow;">小端说：我就是个低低（弟弟）</font></p> <p>下图描述了——大端存储（低字节存储在内存高地址了）：
<img src="https://cdn.jsdelivr.net/gh/HACV/picture/img/1.png" alt="1"></p> <p>下图描述了——小端存储（低字节存储在内存低地址了）：：<img src="https://cdn.jsdelivr.net/gh/HACV/picture/img/2.png" alt="2"></p> <h3 id="_2-2-具体的，大端法和小端法的应用"><a href="#_2-2-具体的，大端法和小端法的应用" class="header-anchor">#</a> 2.2.具体的，大端法和小端法的应用</h3> <p>有的产品用的大端法，有的产品则是小端法。
PS:<strong>这个大端和小端并没有严格按照企业界限来区分</strong>，因为有的企业，它在之前采用的处理器，可能是大端，但是后面的产品中改变了采用的处理器，可能就采用小端法了。
前沿：许多比较新的微处理器使用双端法，也就是说可以把它们配置成作为大端或者小端的机器运行。</p> <h3 id="_2-3-大端法和小端法导致的问题："><a href="#_2-3-大端法和小端法导致的问题：" class="header-anchor">#</a> 2.3.大端法和小端法导致的问题：</h3> <ul><li>1）网络应用程序数据传输</li></ul> <p>在采用不同大小端存储的机器之间通过网络传送二进制数据时候，会导致采用不同大小端存储方式的数据的字节变成反序。
网络字节序
网络上传输的数据都是字节流,对于一个多字节数值，在进行网络传输的时候,先传递哪个字节?也就是说,当接收端收到第一个字节的时候,它将这个字节作为高位字节还是低位字节处理,是一个比较有意义的问题;
UDP/TCP/IP协议规定:
把接收到的第一个字节当作高位字节看待,这就要求发送端发送的第一个字节是高位字节;</p> <p>而在发送端发送数据时，发送的第一个字节是该数值在内存中的起始地址处对应的那个字节,也就是说,该数值在内存中的起始地址处对应的那个字节就是要发送的第一个高位字节(即:高位字节存放在低地址处);
由此可见,多字节数值在发送之前,在内存中因该是以大端法存放的;所以说,网络字节序是大端字节序;</p> <p>比如,我们经过网络发送整型数值0x12345678时,在80x86平台中,它是以小端发存放的,在发送之前需要使用系统提供的字节序转换函数将其转换成大端法存放的数值;</p> <p>常见CPU的宇节序
大端（big Endian）: PowerPC、IBM、 Sun
小端（little Endian）:x86、DEC
<strong>ARM既可以工作在大端模式,也可以工作在小端模式</strong></p> <ul><li>2）反汇编的时候</li></ul> <p>（—未完待续）</p> <h3 id="_2-4-如何判别大端和小端"><a href="#_2-4-如何判别大端和小端" class="header-anchor">#</a> 2.4.如何判别大端和小端</h3> <p>1）我们可以根据C语言中的，联合体来判断，该系统是大端还是小端。
因为，联合体变量总是从低地址存储。</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">union</span> test
	<span class="token punctuation">{</span>
		<span class="token keyword">int</span> a<span class="token punctuation">;</span>
		<span class="token keyword">char</span> c<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>demo<span class="token punctuation">;</span>
	
	demo<span class="token punctuation">.</span>a<span class="token operator">=</span><span class="token number">0x01ffff03</span><span class="token punctuation">;</span>
	<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d&quot;</span><span class="token punctuation">,</span>demo<span class="token punctuation">.</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token keyword">if</span><span class="token punctuation">(</span><span class="token number">0x03</span><span class="token operator">==</span>demo<span class="token punctuation">.</span>c<span class="token punctuation">)</span> 
	<span class="token punctuation">{</span>
		<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;这个机器是小端存储！&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
	<span class="token punctuation">}</span>
	<span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token number">0x00</span><span class="token operator">==</span>demo<span class="token punctuation">.</span>c<span class="token punctuation">)</span> 
	<span class="token punctuation">{</span>
		<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;这个机器是大端存储！&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">else</span>
	<span class="token punctuation">{</span>
		<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;无法判断机器类型！&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><p>显然，
要是小端存储，那么（低字节）0x03在低地址，
要是大端存储，那么（高字节）0x00在低地址。
所以，打印出3就是小端存储。打印出0那就是大端存储。
笔者的电脑是采用的intel的X86CPU，是小端存储。</p> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>输出是3
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_3-概念辨析"><a href="#_3-概念辨析" class="header-anchor">#</a> 3.概念辨析</h2> <h3 id="_3-1-终端"><a href="#_3-1-终端" class="header-anchor">#</a> 3.1.终端</h3> <p>计算机中的终端：是所有<strong>输入输出</strong>设备的『总称』。</p> <ul><li>键盘，鼠标，摄像头</li> <li>屏幕，打印机</li></ul> <p>虚拟机那个黑框框。是终端，是『<strong>虚拟终端</strong>』，不是真实存在的<br>
输入可以在这，输出也在这出，又输入有输出</p> <ul><li>终端在我们系统的级别分，大致如下：</li> <li>1、Alt + Ctrl + F1、F2、F3、F4、F5、F6	<strong>字符终端</strong>   pts (pseudo terminal slave) 指伪终端。</li> <li>2、Alt + F7		<strong>图形终端</strong></li> <li>3、ssh、telnet...		<strong>网络终端</strong>（比如用Xshell啥的，通过网络传输到主机上）</li></ul> <h3 id="_3-2-僵尸进程（zombie）"><a href="#_3-2-僵尸进程（zombie）" class="header-anchor">#</a> 3.2.僵尸进程（Zombie）</h3> <ul><li>参考<a href="https://zh.wikipedia.org/wiki/%E5%83%B5%E5%B0%B8%E8%BF%9B%E7%A8%8B" target="_blank" rel="noopener noreferrer">wiki<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>僵尸进程（僵死进程）: 进程终止，父进程尚未回收，子进程残留资源（PCB）存放于内核中，变成僵尸（Zombie）进程。

注意:僵尸进程是不能使用kill命令清除掉的。因为kill命令只是用来终止进程的，而僵尸进程已经终止。

思考！用什么办法可清除掉僵尸进程呢？
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li><p><strong>僵尸进程</strong>: （死亡的子进程，但不回收）进程终止，父进程尚未回收，子进程残留资源（PCB）存放于<strong>内核</strong>中，变成僵尸（Zombie）进程
（父进程有义务将子进程回收。如果子进程死完之后，要是父进程不给子进程收尸，子进程就成僵尸了）</p></li> <li><p>变成僵尸进程的危害?</p></li> <li><div class="language-txt line-numbers-mode"><pre class="language-text"><code>1、正常进程结束之后，0-3G的进程（用户空间）地址空间，都会被释放。子进程整个0-3G的地址空间都被释放。
2、但是，唯独PCB残留到内核当中，残留的目的是，为了让父进程给他报仇。因为，子进程死了，不留下点什么痕迹，父进程怎么知道你子进程是怎么死的？？他杀，还是自杀『自行结束』
3、父进程可以通过PCB来获取它的死亡状态，如果你是自杀，还算了
4、如果你是他杀，父进程需要采取措施，给你报仇？？？PCB存在的意义是为了，方便父进程收尸，如果父进程比较粗心大意，不管，那么那个PCB就一直存在内核当中。 这样会造成溢出，所以编程的时候，记得要回收僵尸进程
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li></ul> <h3 id="_3-3-孤儿进程"><a href="#_3-3-孤儿进程" class="header-anchor">#</a> 3.3.孤儿进程</h3> <ul><li><strong>孤儿进程</strong>: <strong>父进程先于子进程结束</strong>，则子进程成为孤儿进程，子进程的父进程成为init进程，称为init进程领养孤儿进程。（操作系统让孤儿进程进入“进程孤儿院”（不对吧）。也就是被init进程收养）（有人叫init进程叫进程孤儿院）</li></ul> <h3 id="_3-4-init-进程"><a href="#_3-4-init-进程" class="header-anchor">#</a> 3.4.init 进程</h3> <ul><li>init进程：<strong>系统初始化进程</strong>，是所有用户进程和非调度进程的祖先</li> <li>init进程是『1号进程』，所有进程原先的祖先</li> <li>0号进程是『不会』在操作系统中实际存在的</li></ul> <h3 id="_2-5-内核"><a href="#_2-5-内核" class="header-anchor">#</a> 2.5.内核</h3> <h3 id="_2-6-进程组（作业）"><a href="#_2-6-进程组（作业）" class="header-anchor">#</a> 2.6.进程组（作业）</h3> <p>一个作业通常包括程序、数据和『操作说明书』3部分。
每一个进程由PCB、程序和数据集合组成。这说明程序是进程的一部分，是进程的实体。
因此，一个作业可划分为若干个进程来完成，而每一个进程有其实体————程序和数据集合。</p> <p>1、『<strong>有的书上叫“作业”</strong>，重要！』只不过<font style="background:yellow;">在不同操作系统下，叫法不同而已。</font><br>
2、作业这个概念，早先的时候，来源于BSD操作系统</p> <ul><li>BSD于1980年前后向Unix中增加的一个新特性。</li> <li>代表一个或多个进程的集合。<strong>每个进程都属于一个进程组</strong>。</li></ul> <p>可以用kill，进行进程组ID取负号的方式，来杀死整个组内的进程。</p> <ul><li><strong>组长进程</strong>可以创建一个进程组</li></ul> <h3 id="_2-7-会话（session）"><a href="#_2-7-会话（session）" class="header-anchor">#</a> 2.7.会话（session）</h3> <ul><li>会话（session）：把<font style="background:yellow;">一组『<strong>进程组</strong>』再重新编号</font>，就变成了会话。（圈圈圆圆圈圈，禁止套娃2333）</li></ul> <p>创建一个会话需要注意以下6点<strong>注意事项</strong>：</p> <ol><li>调用进程<strong>不能</strong>是进程组组长，该进程变成新会话<strong>首进程</strong>(session Leader)（简称，“会长”，滑稽）</li> <li>该进程成为一个新进程组的组长进程。</li> <li>需有root权限(ubuntu不需要)</li> <li>新会话丢弃原有的控制终端，该会话没有控制终端（只在后台执行）</li> <li>该调用进程是组长进程，则出错返回</li> <li>建立新会话时，先调用fork, 父进程终止，子进程调用setsid</li></ol> <p>Q：要<strong>会话ID</strong>干啥？</p> <p>A：主要是为了，守护进程用</p> <h3 id="_2-8-守护进程（daemon）『后台开发核心』"><a href="#_2-8-守护进程（daemon）『后台开发核心』" class="header-anchor">#</a> 2.8.守护进程（daemon）『后台开发核心』</h3> <ul><li><strong>守护进程（daemon进程/精灵进程）</strong>：“系统进程”与终端无关，不由用户启动，通常也叫做守护进程，是Linux/Unix『<strong>内核</strong>』专用的特殊进程，是Linux中的<strong>后台服务进程</strong>，通常独立于『控制终端』并且周<strong>期性地</strong>执行某种任务或等待处理某些发生的事件。一般采用以d结尾的名字。</li> <li>守护进程，说白了，就是一个后台系统服务器。</li></ul> <blockquote><ul><li>比如，Linux中的vsftpd，搭建ftp服务器的，安装+启动，httpd，sshd,xinetd</li></ul></blockquote> <ul><li>FAQ：只要是后台的，有没有终端？？没有！</li> <li><b>注意：</b>守护进程不受用户登录、注销的影响，当然，机器重启就另说了,但是厉害的守护进程，比如vsftpd和mysql等，你关机再开机，它也跟着启动</li></ul> <h4 id="创建守护进程"><a href="#创建守护进程" class="header-anchor">#</a> 创建守护进程</h4> <ul><li><p>创建守护进程，最关键的一步是调用setsid函数<strong>创建一个新的会话（Session）</strong>，并成为Session Leader。</p></li> <li><p>当然，你也可以写这样的守护进程，比</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">vim</span> .bashrc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>这是bash解析器的配置文件，每次加载bash的时候都是按照这个去走。
显然设置这个，就可以让完成那样的守护进程。启动放这个里面。</li> <li>为什么，要用会话呢？</li> <li><font style="background:yellow;">因为守护进程都不需要控制终端</font></li></ul></li></ul> <h4 id="_2-创建守护进程模型"><a href="#_2-创建守护进程模型" class="header-anchor">#</a> 2.创建守护进程模型</h4> <ol><li>创建子进程，父进程退出
所有工作在子进程中进行形式上脱离了控制终端</li> <li>在子进程中创建新会话（主要，为了丢弃终端）
　　	setsid()函数
　　	使子进程完全独立出来，脱离控制</li> <li>改变当前目录为根目录
　　	chdir()函数
　　	防止占用可卸载的文件系统（比如，U盘）
　　	也可以换成其它路径</li> <li>重设文件权限掩码
　　	umask()函数
　　	防止继承的文件创建屏蔽字拒绝某些权限
　　	增加守护进程灵活性</li> <li>关闭文件描述符
　　	继承的打开文件不会用到，浪费系统资源，无法卸载</li> <li>开始执行守护进程核心工作（守护进程主逻辑）</li> <li>守护进程退出处理程序模型（几乎不会用，毕竟守护进程一般不退出）</li></ol> <h2 id="参考资料"><a href="#参考资料" class="header-anchor">#</a> 参考资料</h2> <ul><li>《鸟哥的Linux私房菜》</li> <li>张小方Blog，<a href="http://balloonwj.gitee.io/cpp-guide-web/" target="_blank" rel="noopener noreferrer">高性能服务器开发Gitee版<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li> <li>张小方Blog，<a href="https://balloonwj.github.io/cpp-guide-web/" target="_blank" rel="noopener noreferrer">高性能服务器开发GitHub版<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div> <div class="page-edit"><!----> <!----></div> <!----> </div> <!----></div></div>
    <script src="/assets/js/app.c70e21ad.js" defer></script><script src="/assets/js/68.68f45e5e.js" defer></script>
  </body>
</html>
